package com.tbsoft.trail.service;

import java.util.ArrayList;
import java.util.List;

import com.tbsoft.trail.dao.PurchaseOrderDao;
import com.tbsoft.trail.model.PurchaseOrder;
/**
 * @desc 订单处理service
 * @author lizhenhua
 *
 */
public class PurchaseOrderService {

	private PurchaseOrderDao purchaseOrderDao;

	public PurchaseOrderDao getPurchaseOrderDao() {
		return purchaseOrderDao;
	}

	public void setPurchaseOrderDao(PurchaseOrderDao purchaseOrderDao) {
		this.purchaseOrderDao = purchaseOrderDao;
	}

	/**
	 * @desc 批量保存数据，并返回所有生成的id
	 * @param orders
	 * @return
	 */
	public List<Integer> savePurchaseOrders(List<PurchaseOrder> orders) {
		List<Integer> keys = new ArrayList<Integer>();
		for (PurchaseOrder order : orders) {
			Integer key = getPurchaseOrderDao().saveOrder(order);
			keys.add(key);
		}
		return keys;
	}

	/**
	 * @desc 根据ID获取订单对象
	 * @param id
	 * @return
	 */
	public PurchaseOrder getOrder(Integer id) {
		return this.getPurchaseOrderDao().getOrderById(id);
	}
}
